﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using Crude.Core;
using Crude.VisualStudioAddin.Forms;

namespace Crude.VisualStudioAddin.Actions
{
    public class UpdateProjectObjectModelAction : BaseProjectAction
    {
        public override string Name
        {
            get { return "UpdatePOM"; }
        }

        public override string Caption
        {
            get { return "Update project pom file"; }
        }

        public override string Tooltip
        {
            get
            {
                return "Update project pom file with the recent project changes"; ;
            }
        }

        public override BaseProjectAction.ProjectCrudeStatus CrudeStatus
        {
            get { return ProjectCrudeStatus.Crude; }
        }

        protected override void InternalExecuteAction(EnvDTE80.DTE2 applicationObject, EnvDTE.Project project)
        {
            Core.Project crudeProject = new Core.Project(project.FullName);

            string pomFile = string.Format("{0}\\{1}.pom.xml",
               crudeProject.ProjectDirectory, crudeProject.AssemblyName);

            if (applicationObject.SourceControl.IsItemUnderSCC(pomFile) &&
               !applicationObject.SourceControl.IsItemCheckedOut(pomFile))
            {
                applicationObject.SourceControl.CheckOutItem(pomFile);
            }

            UpdatePOMSettingsForm form = new UpdatePOMSettingsForm();
            form.ShowDialog();

            UpdateProjectObjectModel updateProjectObjectModel = new UpdateProjectObjectModel();
            updateProjectObjectModel.Update(project.FullName, form.OnlyCrudeDependencies, 
                form.ResolveToRemoteDependencyVersion);           

        }

    }
}
